import { storageLocal } from "@pureadmin/utils";

const LOCAL_NAME = "canvasStorage";

export interface CanvasData {
  nodes: Array<any>;
  edges: Array<any>;
}

export interface Canvas {
  id?: string;
  uuid: string;
  name: string;
  data: CanvasData;
  file?: string;
}

export interface CanvasState {
  active: string;
  canvas: Canvas[];
}

export function defaultSetting(): CanvasState {
  return {
    active: "",
    canvas: [],
  };
}

export function getLocalState(): CanvasState {
  const localSetting: CanvasState | undefined =
    storageLocal().getItem<CanvasState>(LOCAL_NAME);
  return { ...defaultSetting(), ...localSetting };
}

export function setLocalState(canvasWindow: CanvasState): void {
  storageLocal().setItem(LOCAL_NAME, canvasWindow);
}

export function removeLocalState() {
  storageLocal().removeItem(LOCAL_NAME);
}
